import { propsStatus } from './poolType'

const { vIf, vShow } = propsStatus

export function render(vm, propPool) {
  const _data = vm.$data

  for (const [node, info] of propPool) {
    switch (info.type) {
      case vIf:
        info.comment || (info.comment = document.createComment(vIf))
        !_data[info.prop] && (node.parentNode.replaceChild(info.comment, node))
        break
      case vShow:
        !_data[info.prop] && (node.style.display = 'none')
        break;
      default:
        break;
    }
  }
}

export function update(vm, key, propPool) {
  const _data = vm.$data

  for (const [node, info] of propPool) {
    if (info.prop === key) {
      switch (info.type) {
        case vIf:
          _data[info.prop]
            ? (info.comment.parentNode.replaceChild(node, info.comment))
            : (node.parentNode.replaceChild(info.comment, node))
          break
        case vShow:
          node.style.display = _data[info.prop] ? '' : 'none'
          break;
        default:
          break;
      }
    }
  }
}